package com.bree.erp.jsf.view;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;

import com.bree.erp.entity.InventoryAudit;
import com.bree.erp.jsf.datatable.LazyBreeDataModel;
import com.bree.erp.service.InventoryAuditService;

@ManagedBean(name="dtInventoryAuditLazyView")
@ViewScoped
public class InventoryAuditLazyView {

	private static Logger LOG = Logger.getLogger(InventoryAuditLazyView.class);

    private LazyDataModel<InventoryAudit> lazyModel;
    
    @EJB
    private InventoryAuditService iaService;
    
    private InventoryAudit selectedItem;
    
    @PostConstruct
    public void init() {
    	lazyModel = new LazyBreeDataModel<InventoryAudit, InventoryAuditService, Long>(iaService, 0L);
    }
    
   public void onRowSelect(SelectEvent event) {
       FacesMessage msg = new FacesMessage("Item Selected", ((InventoryAudit) event.getObject()).getId() + "");
       FacesContext.getCurrentInstance().addMessage(null, msg);
   }

	/**
	 * @return the selectedItem
	 */
	public InventoryAudit getSelectedItem() {
		return selectedItem;
	}

	/**
	 * @param selectedItem the selectedItem to set
	 */
	public void setSelectedItem(InventoryAudit selectedItem) {
		this.selectedItem = selectedItem;
	}

	/**
	 * @return the lazyModel
	 */
	public LazyDataModel<InventoryAudit> getLazyModel() {
		return lazyModel;
	}

}
